#!/usr/bin/env python
# -*- coding: utf-8 -*-

from stanfordcorenlp import StanfordCoreNLP


class nlp_string(object):
    def __init__(self, path, port=9000):
        self.nlp = StanfordCoreNLP(path_or_host=path, port=port)

    def get_result(self, value, format='json', lang='zh'):
        ret_dict = dict()
        tokenize = {'annotators': 'tokenize', 'pipelineLanguage': lang, 'outputFormat': format}
        pos = {'annotators': 'pos', 'pipelineLanguage': lang, 'outputFormat': format}
        ner = {'annotators': 'ner', 'pipelineLanguage': lang, 'outputFormat': format}

        #
        # Tokenize: ['清华', '大学', '位于', '北京', '。']
        tokenize = self.nlp.annotate(value, properties=tokenize)
        pos = self.nlp.annotate(value, properties=pos)
        ner = self.nlp.annotate(value, properties=ner)
        ret_dict = {'tokenize': tokenize, 'pos': pos, 'ner': ner}
        # 这里具体数据格式,还要确定
        print(ret_dict)
        return ret_dict


nlp = nlp_string(path='http://59.110.125.161', port=5000)
nlp.get_result(value='清华大学位于北京市')
